home *** CD-ROM | disk | FTP | other *** search
- /*
- * display.h,v 1.0 1996/03/18 14:18:33 miksic Exp
- */
-
- /* DISPLAY.H -- include file for Gizmo-2 seven segment display
- * Copyright (c) 1993 by Echelon Corporation.
- * All Rights Reserved.
- */
-
- // This NEURON C #include file contains code to drive the Motorola MC14489
- // seven-segment display controller chip, interfaced to the NEURON CHIP
- // using Neurowire output mode.
-
- // Pin IO_8 is the Neurowire clock, pin IO_9 is the serial output data
- // Pin IO_2 is the chip select (may be modified).
-
- // Change the following #defines if there are fewer than 4 digits
- // in the display. The rightmost digit is numbered 0.
-
- #define NUM_DIGITS 4
- #define MAX_NUMBER 9999
- #define MIN_NUMBER -999
-
- /////////////////////// DECLARATIONS ////////////////////////////////
-
- IO_8 neurowire master select( IO_2 ) IO_seven_seg;
- IO_2 output bit IO_7_seg_select = 1; // Initially unselected
-
- unsigned char display_reg[ 3 ]; // 24 bits for 7-seg display reg
- unsigned char config_reg; // 8 bits for 7-seg config reg
-
- unsigned char display_reg_copy[ 3 ];
- unsigned char config_reg_copy;
-
-
- //////////////////// CONTROL DISPLAY HARDWARE //////////////////////
-
- void shift_out( void ) { // update device hardware registers
- memcpy( display_reg_copy, display_reg, 3 );
- config_reg_copy = config_reg;
- io_out( IO_seven_seg, &config_reg_copy, 8 );
- io_out( IO_seven_seg, display_reg_copy, 24 );
- }
-
- void clear_display( void ) { // clear image of device registers
- display_reg[ 0 ] = 0x80; // max brightness
- display_reg[ 1 ] = 0; // blanks on all digits
- display_reg[ 2 ] = 0;
- config_reg = 0xFF; // special decode on banks 1-5, normal mode
- }
-
- ////////////////// SINGLE-CHARACTER DISPLAY FUNCTIONS //////////////
-
- void display_decimal( int digit_number, int decimal ) {
- // display decimal number ( 0 - 9 ) on a digit
-
- display_reg[ 2 - digit_number / 2 ] |=
- ( digit_number & 1 ) ? ( decimal << 4 ) : decimal;
- config_reg &= ~( 1 << ( digit_number + 1 ) );
- }
-
- void display_char( int digit_number, int character, boolean is_numeric ) {
- // display a character from the Gizmo character set
-
- display_reg[ 2 - digit_number / 2 ] |=
- ( digit_number & 1 ) ? ( character << 4 ) : character;
- if( is_numeric ) config_reg &= ~( 1 << ( digit_number + 1 ) );
- }
-
- void display_DP( int digit_number ) {
- // display decimal point on a digit
- display_reg[ 0 ] |= ( digit_number + 1 ) << 4;
- }
-
- void display_minus( int digit_number ) {
- // display minus sign on a digit
- display_reg[ 2 - digit_number / 2 ] |=
- ( digit_number & 1 ) ? 0xD0 : 0x0D;
- }
-
- //////////////////////// Blank the display /////////////////////////
-
- void blank_display (void) {
- clear_display();
- shift_out();
- }
- ///////////////////////// DISPLAY DECIMAL NUMBER ///////////////////
-
- void display_number( long number, int dp_digit );
-
- #define NO_DP -1 /* display number without decimal point */
- #define ALL_DPS -2 /* display number with all decimal points */
-
- void display_number( long number, int dp_digit )
- {
- int digit;
- long local_num;
-
- clear_display( ); // clear image of display registers
-
- if( ( number > MAX_NUMBER ) || ( number < MIN_NUMBER ) ) {
- display_reg[ 1 ] = display_reg[ 2 ] = 0xDD;
- shift_out( ); // update hardware
- return; // display "----" for overrange
- }
- if( number < 0 ) {
- display_minus( NUM_DIGITS - 1 ); // leading minus sign
- local_num = - number;
- } else local_num = number;
-
- for( digit = 0;
- local_num || ( digit <= max( dp_digit, 0 ) ); digit++ ) {
- // convert binary to decimal with leading zero suppress
- if( ( number < 0 ) && ( digit == NUM_DIGITS - 1 ) ) break;
- display_decimal( digit, ( int )( local_num % 10 ) );
- local_num /= 10;
- }
- display_DP( dp_digit ); // display decimal point
- shift_out( ) ; // update hardware
- }
-
- ///////////////////////////////////////////////////////////////
-
- typedef struct {
- unsigned character;
- boolean is_numeric;
- char ascii;
- } char_table_t; // Gizmo character set table
-
- const char_table_t char_table[ ] = {
- 0xA, TRUE, 'A',
- 0xC, TRUE, 'C',
- 0xE, TRUE, 'E',
- 0xF, TRUE, 'F',
- 0x2, FALSE, 'H',
- 0x1, TRUE, 'I',
- 0x4, FALSE, 'J',
- 0x5, FALSE, 'L',
- 0x0, TRUE, 'O',
- 0x8, FALSE, 'P',
- 0x5, TRUE, 'S',
- 0xA, FALSE, 'U',
- 0xC, FALSE, 'Y',
- 0x2, TRUE, 'Z',
- 0xB, TRUE, 'b',
- 0x1, FALSE, 'c',
- 0xD, TRUE, 'd',
- 0x3, FALSE, 'h',
- 0x1, TRUE, 'l',
- 0x6, FALSE, 'n',
- 0x7, FALSE, 'o',
- 0x9, FALSE, 'r',
- 0xB, FALSE, 'u',
- 0xD, FALSE, '-',
- 0xE, FALSE, '=',
- 0xF, FALSE, '%', // degrees
- 0x0, FALSE, ' ',
- 0x0, TRUE, '0',
- 0x1, TRUE, '1',
- 0x2, TRUE, '2',
- 0x3, TRUE, '3',
- 0x4, TRUE, '4',
- 0x5, TRUE, '5',
- 0x6, TRUE, '6',
- 0x7, TRUE, '7',
- 0x8, TRUE, '8',
- 0x9, TRUE, '9',
- 0xFF };
-
- /////////////////////////// DISPLAY ASCII STRING //////////////////////
-
- void display_string( const char * s, int dp_digit ) {
- // displays first 4 characters of a string with optional decimal point
-
- const char_table_t * table_ptr;
- int digit;
-
- clear_display( ); // all non-displayable chars show as blank
-
- for( digit = NUM_DIGITS - 1; digit >= 0; digit--, s++ ) {
-
- for( table_ptr = char_table; table_ptr->character != 0xFF;
- table_ptr++ ) {
-
- if( * s == table_ptr->ascii ) { // match char in table
- display_char( digit, table_ptr->character,
- table_ptr->is_numeric );
- break;
- }
- }
- }
- display_DP( dp_digit ); // display decimal point
- shift_out( ); // update hardware
- }
-
-
-